package com.lebang.controller.api.bus;

import com.lebang.feign.bus.BusRecordFeign;
import com.lebang.model.RequestUserInfo;
import com.lebangweb.common.TextUtil;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户搜索公交线路记录
 * @Author: ljx
 * @Date: 2020/10/9
 */
@Api("用户搜索公交线路记录")
@RestController
@RequestMapping("/api/buss")
public class BusRecordApi {
    @Autowired
    private BusRecordFeign busRecordFeign;

    /**
     * 添加当前城市用户搜索公交线路记录
     * @param request
     * @param cityId
     * @param route
     * @param routeId
     * @param endStan
     * @param routeNum
     * @return
     */
    @ApiOperation("添加当前城市用户搜索公交线路记录")
    @PostMapping("/record/add")
    public JsonData add(HttpServletRequest request,
                        @ApiParam(name = "城市id") @RequestParam("cityId") String cityId,
                        @ApiParam(name = "城市id") @RequestParam("route") String route,
                        @ApiParam(name = "公交线路")@RequestParam("routeId") String routeId,
                        @ApiParam(name = "公交线路")@RequestParam("endStan") String endStan,
                        @ApiParam(name = "路线编号")@RequestParam("routeNum") String routeNum
    ) {
        RequestUserInfo requestUserInfo = new RequestUserInfo(request);
        if (TextUtil.isEmpty(cityId) || TextUtil.isEmpty(route) || TextUtil.isEmpty(routeId) ||TextUtil.isEmpty(endStan) || TextUtil.isEmpty(routeNum)) {
            return Callback.fail("201", "添加记录失败");
        }
        return busRecordFeign.add(requestUserInfo,cityId, route,routeId,endStan,routeNum);
    }

    /**
     * 查询当前城市用户搜索公交线路记录
     * @param request
     * @return
     */
    @ApiOperation("查询当前城市用户搜索公交线路记录")
    @PostMapping("/record/get")
    public JsonData get(HttpServletRequest request, @ApiParam(name = "城市id") @RequestParam(value = "cityId") String cityId) {
        RequestUserInfo requestUserInfo = new RequestUserInfo(request);
        return busRecordFeign.get(requestUserInfo,cityId);
    }

    /**
     * 删除当前城市用户搜索公交线路记录
     * @param request
     * @param cityId
     * @return
     */
    @ApiOperation("删除当前城市用户搜索公交线路记录")
    @PostMapping("/record/del")
    public JsonData del(HttpServletRequest request,@ApiParam(name = "城市id") @RequestParam(value = "cityId") String cityId ,@RequestParam(value = "routeId",required = false) String routeId) {
        RequestUserInfo requestUserInfo = new RequestUserInfo(request);
        return busRecordFeign.del(requestUserInfo,cityId,routeId);
    }
}
